<?php
define('IN_UCHOME', '1');
require_once 'api/function_common.php';
require_once 'api/config.php';
require_once 'api/class_mysql.php';
require_once 'api/function_file_cp.php';
require_once 'api/function_image.php';

// 时间
$mtime = explode(' ', microtime());
$_SGLOBAL['timestamp'] = $mtime[1];
$_SGLOBAL['supe_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];

// 程序目录
define('S_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
$email = $_REQUEST['e'];
$pwmd5 = $_REQUEST['p'];

$auth = checkAuth($email, $pwmd5);
$siteurl = "http://" . $_SERVER['HTTP_HOST'];
file_put_contents("./siteurl.html", $siteurl);
$arr = array(
		"status" => 0
);

if ($_POST["f"] == "upload") {
	
	if (! $auth) {
		$arr['err'] = "用户未登录，或者登陆失败";
		echo json_encode($arr);
		exit();
	}
	// $data = file_get_contents('php://input');
	$postTag = file_put_contents("./api_post.html", print_r($_POST, true));
	if (! $postTag) {
		$arr['err'] = "传入参数为空";
		echo json_encode($arr);
		exit();
	}
	$picTag = file_put_contents("./api_post.png", file_get_contents($_FILES['_file']['tmp_name']));
	// file_put_contents("./api1.html",print_r($_FILES,true));
	
	if (! $picTag) {
		$arr['err'] = "图片保存失败";
		echo json_encode($arr);
		exit();
	}
	list($width, $height, $type, $attr) = getimagesize("./api_post.png");
	$arr['status'] = 1;
	$arr['pic'] = $siteurl . "/api_post.png?t=" . time();
	$arr['width'] = $width;
	$arr['height'] = $height;
	echo json_encode($arr);
}

if ($_GET["f"] == "upload") {
	
	if (! $auth) {
		$arr['err'] = "用户未登录，或者登陆失败";
		echo json_encode($arr);
		exit();
	}
	$picTag = file_put_contents("./api_get.png", file_get_contents($_GET['url']));
	
	if (! $picTag) {
		$arr['err'] = "图片保存失败";
		echo json_encode($arr);
		exit();
	}
	
	list($width, $height, $type, $attr) = getimagesize("./api_get.png");
	$arr['status'] = 1;
	$arr['pic'] = $siteurl . "/api_get.png?t=" . time();
	$arr['width'] = $width;
	$arr['height'] = $height;
	echo json_encode($arr);

}

if ($_GET["f"] == "logintest") {
	echo $auth ? 1 : 3;
	exit();
}

?>